package chapter12.exception_.HomeWork;

import java.util.Scanner;

/**
 * @Auther: Tx
 * @Date: 2022/5/3 20:08
 */
//从控制台输入两个参数H
public class HomeWork01 {
    public static void main(String[] args) {
        try {
            if (args.length != 2) {
                throw new ArrayIndexOutOfBoundsException("参数个数不对");
            }
            //这里要捕捉格式不对的异常
            int n1 = Integer.parseInt(args[0]);
            int n2 = Integer.parseInt(args[1]);
            //这里捕捉数学异常，防止除零
            System.out.println(call(n1,n2));
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(e.getMessage());
        }catch (NumberFormatException e){
            System.out.println("输入的数据格式不对");
        }catch (ArithmeticException e){
            System.out.println("被除数不能是0");
        }


    }

    public static double call(int n1, int n2) {
        return n1 / n2;

    }
}
